﻿using Bottle.CommunityForum.IBLL;
using Bottle.CommunityForum.IDAL;
using Bottle.CommunityForum.Model;
using Bottle.CommunityForum.Model.Param;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Bottle.CommunityForum.BLL
{
    public partial class RoleInfoService : BaseService<RoleInfo>, IRoleInfoService
    {
        /// <summary>
        /// 多条件查询
        /// </summary>
        /// <typeparam name="S"></typeparam>
        /// <param name="queryRoleParam">条件实体</param>
        /// <param name="ordlambda">排序</param>
        /// <returns></returns>
        public IQueryable<RoleInfo> QueryWhereLoadPage<S>(RoleInfoParam queryRoleParam, Expression<Func<RoleInfo, S>> ordlambda)
        {
            //获取所有角色信息
            var Param = Db.RoleInfoDal.QueryEntitys(u => true);
            //关键字查询
            if (!string.IsNullOrEmpty(queryRoleParam.Keyword))
            {
                Param = Param.Where(u => u.rolename.Contains(queryRoleParam.Keyword) || u.content.Contains(queryRoleParam.Keyword))
                    .AsQueryable();
            }
            //角色备注查询
            if (!string.IsNullOrEmpty(queryRoleParam.content))
            {
                Param = Param.Where(u => u.content.Contains(queryRoleParam.content))
                    .AsQueryable();
            }
            //角色名称
            if (!string.IsNullOrEmpty(queryRoleParam.rolename))
            {
                Param = Param.Where(u => u.rolename.Contains(queryRoleParam.rolename))
                    .AsQueryable();
            }
            //获取总数
            queryRoleParam.totle = Param.Count();
            //排序（正序/倒序）
            if (queryRoleParam.isOrder)
            {
                Param = Param.OrderBy(ordlambda)
                    .Skip(queryRoleParam.pageSize * (queryRoleParam.pageIndex - 1))
                    .Take(queryRoleParam.pageSize)
                    .AsQueryable();
            }
            else
            {
                Param = Param.OrderByDescending(ordlambda)
                    .Skip(queryRoleParam.pageSize * (queryRoleParam.pageIndex - 1))
                    .Take(queryRoleParam.pageSize)
                    .AsQueryable();
            }

            return Param;
        }
    }
}
